var page = require('webpage').create();


var tabUrl = 'https://www.baidu.com/s?ie=utf-8&f=8&rsv_bp=0&rsv_idx=1&tn=baidu&wd=pcsoft&rsv_pq=b28ce2fd00001c20&rsv_t=aa2beLVeFxdGbtZFk6VaXI%2FKnDh7nvqz9Lo9xXP%2FiqEavkcem1DiE5xKn68&rqlang=cn&rsv_enter=1&rsv_sug3=7&rsv_sug1=6&rsv_sug7=100&rsv_sug2=0&inputT=4364&rsv_sug4=5035';

var nextURL = false;
page.open(tabUrl, function(status){
	if(status !== "success") {
		console.log('fail to load');
		phantom.exit();
	}else {
			var t = page.evaluate(function() {

				var d = document.querySelectorAll('.c-container  .f13 .c-showurl')[0];
				return d.href;
			})
			console.log(t);
			nextURL = t;
		
			page.render('baidu.png');
			

	}
})

page.onNavigationRequested = function() {
	console.log("页面发生跳转");
}
//page.onUrlChanged = function(targetURL ) {
//	console.log(targetURL );
//}


setInterval(function(){
	if(nextURL != false) {
		console.log(nextURL);
		var newPage = require('webpage').create();
		newPage.open("http://www.toastmemo.cn", function(s){
			console.log(s);
			if(s == "success") {
				
				newPage.render('baidu2.png');
				
			}
			phantom.exit();
		})
		
	}
	console.log(123);
},10)


   newPage.onConsoleMessage = function(msg) {
	console.log(msg);
};